﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MyBind;
using DAL;


public partial class Communicate_BBSCatMangr : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.GridView1.DataKeyNames = new string[] {"id"};
        if(!IsPostBack)
        {
            bind();
        }
    }

    //修改
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.NewEditIndex].Value.ToString();
        Response.Redirect("BBSCatMangr.aspx?id=" + id);
    }

    //添加大类
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("BBSCatMangr.aspx");
    }

    //添加脚本
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string attriValue = "javascript:return confirm('确定删除吗？')";
                ((LinkButton)e.Row.Cells[3].Controls[0]).Attributes.Add("onClick", attriValue);
            }
        }
    }
    //删除操作
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        DAL.bbsCatalog dal = new bbsCatalog();
        int id = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
        if (dal.Delete(id)>0)
        {
            WriteScript.Mesg(this.Response,"删除成功！");
            bind();
        }
    }

    protected void bind()
    {
        DAL.bbsCatalog dal = new bbsCatalog();
        DataTable dt=dal.GetList("").Tables[0];
        this.GridView1.DataSource = dt.DefaultView;
        GridView1.DataBind();
    }

    protected void bind(DataTable dt)
    {
        this.GridView1.DataSource = dt.DefaultView;
        GridView1.DataBind();
    }
}
